package com.hkfn.rfb.common.view;

import android.view.MotionEvent;
import android.view.View;
import android.view.ViewConfiguration;

public class ChildTouchListener implements View.OnTouchListener{

    private float downX;
    private float downY;
    private float touchSlop;
    private View view;

    public ChildTouchListener(View view){
        this.view = view;
        touchSlop = ViewConfiguration.get(view.getContext()).getScaledTouchSlop();
    }

    @Override
    public boolean onTouch(View v, MotionEvent event) {
        switch (event.getActionMasked()){
            case MotionEvent.ACTION_DOWN:
                downX = event.getX();
                downY = event.getY();
                break;
            case MotionEvent.ACTION_UP:
                if (Math.abs(event.getY() - downY) < touchSlop && Math.abs(event.getX() - downX) < touchSlop){
                    view.performClick();
                }
                break;
        }
        return false;
    }
}